home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
machserver
/
tests
/
kitten
/
RCS
/
kitten.c,v
< prev
Wrap
Text File
|
1992-07-16
|
4KB
|
237 lines
head 1.3;
branch ;
access ;
symbols srv030:1.3 srv027:1.3 srv026:1.3 srv024:1.3 srv021:1.3 srv018:1.3 srv014:1.3 srv010:1.3 srv008:1.3 srv007:1.3 srv006:1.3 srv004:1.3;
locks ; strict;
comment @ * @;
1.3
date 92.03.23.15.10.10; author kupfer; state Exp;
branches ;
next 1.2;
1.2
date 91.12.12.22.36.52; author kupfer; state Exp;
branches ;
next 1.1;
1.1
date 91.12.01.22.43.56; author kupfer; state Exp;
branches ;
next ;
desc
@Small "cat".
@
1.3
log
@Add support for /dev/console and optionally shutting down rather than
just exiting.
@
text
@/* small "cat" program. */
#ifndef lint
static char rcsid[] = "$Header: /user5/kupfer/spriteserver/tests/kitten/RCS/kitten.c,v 1.2 91/12/12 22:36:52 kupfer Exp Locker: kupfer $";
#endif
#include <stdlib.h>
#include <stdio.h>
#include <sys.h>
#include <sys/fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <test.h>
#include <unistd.h>
#define USE_MALLOC 1
#define BUF_SIZE 8192
#define USE_CONSOLE 1 /* 0 to use Test_foo to write each line */
#define DO_SHUTDOWN 0 /* 0 to just exit quietly */
static void CatFile();
static void DoFile();
int
main(argc, argv)
int argc;
char *argv[];
{
int i;
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
continue;
}
DoFile(argv[i]);
}
#if DO_SHUTDOWN
(void)Sys_Shutdown(SYS_HALT|SYS_KILL_PROCESSES|SYS_WRITE_BACK, NULL);
#endif
return 0;
}
/*
*----------------------------------------------------------------------
*
* DoFile --
*
* Process the named file.
*
* Results:
* None.
*
* Side effects:
* If it's a text file, its contents are printed. For anything else,
* stat information is given for it.
*
*----------------------------------------------------------------------
*/
static void
DoFile(fileName)
char *fileName;
{
struct stat statBuf;
if (stat(fileName, &statBuf) < 0) {
perror(fileName);
return;
}
if ((statBuf.st_mode & S_IFMT) == S_IFREG) {
CatFile(fileName);
} else {
Test_PutMessage("Type: ");
Test_PutOctal(statBuf.st_mode & S_IFMT);
Test_PutMessage("\nServer: ");
Test_PutDecimal(statBuf.st_serverID);
Test_PutMessage("\nDevice: ");
Test_PutDecimal(statBuf.st_dev);
Test_PutMessage("\nI-number: ");
Test_PutDecimal(statBuf.st_ino);
Test_PutMessage("\nOwner: ");
Test_PutDecimal(statBuf.st_uid);
Test_PutMessage("\n");
}
}
/*
*----------------------------------------------------------------------
*
* CatFile --
*
* Print the contents of a file.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static void
CatFile(fileName)
char *fileName;
{
#ifdef USE_MALLOC
char *buf;
#else
char buf[BUF_SIZE];
#endif
int file; /* file descriptor */
int nChars; /* number of characters read */
#if USE_CONSOLE
int cons; /* console file descriptor */
#endif
#ifdef USE_MALLOC
buf = malloc(BUF_SIZE);
if (buf == NULL) {
Test_PutMessage("malloc failed.\n");
exit(1);
}
#endif
file = open(fileName, O_RDONLY);
if (file < 0) {
perror(fileName);
exit(1);
}
#if USE_CONSOLE
cons = open("/dev/console", O_WRONLY, 0666);
if (cons < 0) {
perror("can't open console");
exit(1);
}
#endif /* USE_CONSOLE */
while ((nChars = read(file, buf, BUF_SIZE)) > 0) {
#if USE_CONSOLE
if (write(cons, buf, nChars) < 0) {
perror("can't write to console");
exit(1);
}
#else
Test_PutString(buf, nChars);
#endif
}
if (nChars < 0) {
perror("read");
exit(1);
}
close(file);
#ifdef USE_MALLOC
free(buf);
#endif
}
@
1.2
log
@Let buffer either be malloc'd or allocated on the stack.
@
text
@d4 1
a4 1
static char rcsid[] = "$Header$";
d9 1
d18 2
d38 3
d70 1
a70 1
exit(1);
d118 3
d131 7
a137 1
perror("open");
d140 1
d143 6
d150 1
@
1.1
log
@Initial revision
@
text
@d3 4
d15 1
d105 3
d109 1
d113 7
d135 3
@